package com.sfh.cp.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RadioGroup;

import com.sfh.cp.R;


/**
 * 功能描述:底部菜单栏
 *
 * @author SunFeihu 孙飞虎
 * @date 2017/11/28
 */
public class WidgetTableMenuLayout extends RadioGroup implements RadioGroup.OnCheckedChangeListener {


    public interface IOnSelectItem {
        void onSelectItem(int position);
    }

    IOnSelectItem onSelectItem;

    public WidgetTableMenuLayout(Context context) {
        super(context);
        init();
    }

    public WidgetTableMenuLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }


    private void init() {

        inflate(getContext(), R.layout.widget_table_menu_layout, this);
        this.setOrientation(HORIZONTAL);
        int p = getContext().getResources().getDimensionPixelSize(R.dimen.y10);
        this.setPadding(0, p, 0, p);
        this.setOnCheckedChangeListener(this);
    }

    public void setOnSelectItem(IOnSelectItem onSelectItem) {
        this.onSelectItem = onSelectItem;
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (onSelectItem == null){
            return;
        }
        switch (checkedId)
        {
            case R.id.rbHome:
            {
                this.onSelectItem.onSelectItem(0);
                break;
            }
            case R.id.rbMass:
            {
                this.onSelectItem.onSelectItem(1);
                break;
            }
            case R.id.rbMsg:
            {
                this.onSelectItem.onSelectItem(2);
                break;
            }
            case R.id.rbMy:
            {
                this.onSelectItem.onSelectItem(3);
                break;
            }
            default:
                break;
        }
    }


}
